package cn.piggy.gateway.center.domain.nginx.service;

import cn.piggy.gateway.center.application.ILoadBalancingService;
import cn.piggy.gateway.center.domain.nginx.model.aggregates.NginxConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;


public abstract class AbstractLoadBalancing implements ILoadBalancingService {

    private Logger logger = LoggerFactory.getLogger(AbstractLoadBalancing.class);

    @Override
    public void updateNginxConfig(NginxConfig nginxConfig) throws Exception {
        // 1. 创建 Nginx 配置文件
        String containerFilePath = createNginxConfigFile(nginxConfig);
        logger.info("步骤1：创建 Nginx 配置文件 containerFilePath：{}", containerFilePath);
        // 2. Linux 版本刷新 nginx 配置文件
        refreshNginxConfigLinux();
        logger.info("步骤2：刷新 Nginx 配置文件 Done！");
    }

    protected abstract String createNginxConfigFile(NginxConfig nginxConfig) throws IOException;

    protected abstract void refreshNginxConfigLinux();

    protected abstract void refreshNginxConfigWindows();
}
